Project 2
Code
///Name: Joshua Bautista
///Period: 6
///Date: 9/17/2015
import java.util.Scanner;
import java.util.Random;
public class Nim
{
public static void main( String[] args)
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
String Pla1, Pla2, cho1;
int pi1, pi2, pi3, chon1, chon2 , chon3 , tot1, tot2, tot3;
pi1 = 1 + r.nextInt(10);
pi2 = 1 + r.nextInt(10);
pi3 = 1 + r.nextInt(10);
System.out.print(" Player 1, enter your name:" );
Pla1 = keyboard.next();
System.out.print(" Player 2, enter your name:" );
Pla2 = keyboard.next();
System.out.println("A:" + pi1 + "B: " + pi2 + "C: " + pi3 );
do
{
System.out.println( Pla1 + ", choose a pile: ");
cho1 = keyboard.next();
if ( cho1.equals("A"))
{
System.out.println(" How many do you want to remove from pile A ");
chon1 = keyboard.nextInt();
tot1 = pi1-chon1;
System.out.println("A:" + pi1 + "B: " + pi2 + "C: " + pi3 );
}
else if ( cho1.equals("B"))
{
System.out.println(" How many do you want to remove from pile B ");
chon2 = keyboard.nextInt();
tot2 = pi2-chon2;
System.out.println("A:" + pi1 + "B: " + pi2 + "C: " + pi3 );
}
else if ( cho1.equals("C"))
{
System.out.println(" How many do you want to remove from pile C ");
chon3 = keyboard.nextInt();
tot3 = pi3-chon3;
System.out.println("A:" + pi1 + "B: " + pi2 + "C: " + pi3 );
}
}
while ( pi1 == 0 && pi2 == 0 && pi3 == 0 );
{
System.out.println("BOqa");
}
}
}
Picture of the output